package com.saber.accumulator;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import com.saber.bean.Report;
import com.saber.bean.ReportItem;



/**
 *
 * @author
 *
 */
public class ReportItemAccumulatorAdapter implements ReportItemAccumulator {



	/**
	 *
	 */
	private static Map<ReportItem.AccumulatorType, ReportItemAccumulator> riaMap;

	/**
	 *
	 */
	static {
		riaMap = new HashMap<ReportItem.AccumulatorType, ReportItemAccumulator>();
		Map<String, ReportItemAccumulator> bmap = new HashMap<String, ReportItemAccumulator>();
		bmap.put("Avg", new Avg());
		bmap.put("Sum", new Sum());
		bmap.put("None", new None());
		for(ReportItemAccumulator ria : bmap.values()) {
			if(ria instanceof ReportItemAccumulatorAdapter) {
				continue;
			}
			for(ReportItem.AccumulatorType type : ria.getSupported()) {
				riaMap.put(type, ria);
			}
		}
	}

	@Override
	public ReportItem.AccumulatorType[] getSupported() {
		return null;
	}

	@Override
	public void accumulate(Report report, ReportItem reportItem, Object value) {
		ReportItemAccumulator ria = riaMap.get(reportItem.getType());
		if(null == ria) {
			throw new RuntimeException("No Report Item Accumulator config for type: " + reportItem.getType());
		}
		ria.accumulate(report, reportItem, value);
	}
}